<?php

session_start();
$studentID = $_SESSION['uname'];
echo $studentID;

require_once '../../commonutils/db/DBConnectionManager.php';


if(isset($_FILES['userfile']))
{
	try
	{
		upload();
	}
	catch(Exception $e)
	{
		echo "<div><h1><center>Cannot upload image</center></h1></div>";
	}
}

function upload()
{
	if(is_uploaded_file($_FILES['userfile']['tmp_name']))
	{
		$imgData = addslashes(file_get_contents($_FILES['userfile']['tmp_name']));

		$s = "update student set picture = '$imgData' where studentID = ".$studentID;
		DBConnectionManager::query($s);
		
		echo "<div><h1><center>Upload successful</center></h1></div>";
	}
	else
	{
		echo "<div><h1><center>Cannot upload image</center></h1></div>";
	}
}
?>

<br>
<hr color="blue">
<p>
<a href="../../StudentIndex.php"> Back </a>
</p>